<%-- 
    Document   : controllergraph
    Created on : 5/12/2010, 09:59:36 PM
    Author     : Daniel
--%>

<%@page import="java.sql.ResultSet" %>
<%@page import="java.sql.Connection"%>
<%
            String data = "";
            String sql = "";
            int upd = 0;
            int errorcode = 0;
            model.ConnectionDB connection = new model.ConnectionDB();
            ResultSet res = null;

             if (request.getParameter("Action").equals("Seek")) {
                sql = "SELECT * FROM consultroute();";

                 try {
                    connection.connect();

                    res = connection.consult(sql);
                    connection.getCon().close();

                    while (res.next()) {

                        if (!data.equals("")) {
                            data += ",";
                        }
                        data += '{';
                        data += "'idRoute' :" + res.getInt(1) + ", ";
                        data += "'source' :'" + res.getString(2) + "', ";
                        data += "'destination': '" + res.getString(3) +"'";
                        data += '}';
                    }
                } catch (Exception e) {
                    out.print(e.getMessage());
                    errorcode = -1;
                    connection.getCon().close();
                  }
           }else{
                sql = "SELECT * FROM inforoutes();";

                 try {
                    connection.connect();

                    res = connection.consult(sql);
                    connection.getCon().close();

                    while (res.next()) {

                        if (!data.equals("")) {
                            data += ",";
                        }
                        data += '{';
                        data += "'idRoute' :" + res.getInt(1) + ", ";
                        data += "'number' :" + res.getInt(2) ;
                        data += '}';
                    }
                } catch (Exception e) {
                    out.print(e.getMessage());
                    errorcode = -1;
                    connection.getCon().close();
                  }
                }
              String json = "{'errorcode' : " + errorcode + ", 'data' : [" + data + "]}";
            out.print(json);
%>
